<?php
defined('BASEPATH') OR exit('No direct script access allowed');
//字典字段管理
class Dict_field extends CommonController {

	function __construct(){
		
		parent::__construct();
		$this->load->model('System/DictFieldModel','CurModel');
		
	}
	
	
	//start
	/**
	* @name 获取列表
	* @param page ture char 页面
	* @param size ture char 数量
	* @return 成功返回1
	*/
	//end
	function get_list(){
		$user_id = $this->user_id;
		$dist_id = $this->input->post('f[dict_id]',null,0);
		
		
		$filter = array('name','dict_id');
		$arr = array(
			'filter'=>$filter
		);
		
		$result = parent::_get_list($arr);
		if(!$result){
			$this->err_out($this->getError());
		}
		
		$this->load->model('System/DictModel','DistModel');
		$dist = $this->DistModel->get_info($dist_id);
		if(!$dist){
			$this->err_out('数据不存在');
		}
		$list = $result['list'];
		foreach($list as $key=>$val){
			$list[$key]['dict_name'] = $dist['name'];
			
		}
		$result['list'] = $list;
		
		$this->data_out($result);
	}
	
	function info_out($info){
		
		
		
		
		return $info;
	}
	
	//start
	/**
	* @name 获取信息
	* @param id ture char ID
	* @return 成功返回1
	*/
	//end
	function get_info(){
		$user_id = $this->user_id;
		
		$result = parent::_get_info();
		if(!$result){
			$this->err_out($this->getError());
		}
		
		$this->data_out($result);
	}
	
	//start
	/**
	* @name 获取信息
	* @param id ture char ID
	* @return 成功返回1
	*/
	//end
	function save(){
		
		$filter = array(
			'code'=>'代码不能为空',
			'name'=>'名称不能为空',
			'dict_id'=>'所属字典不能为空'
		);
		if(!preg_match('/[a-zA-Z]{1}[a-zA-Z0-9]/i', $_POST['code'])){
			//$this->err_out('名称必须是英文字母开头和数字的组合');
		}
		$exists = array('name');
		
		$post = array('name','code','type','dict_id');
		$farr = array(
			'post'=>$post,
			'filter'=>$filter,
			'exists'=>$exists
		);
		
		$result = parent::_save($farr);
		if(!$result){
			$this->err_out($this->getError());
		}
		
		$this->add_log("保存字段【{$result['id']}】信息",'role');
		
		$this->data_out($result);
	}
	


	
	//start
	/**
	* @name 删除
	* @param id ture int ID
	* @return 成功返回1
	*/
	//end
	function del(){
		
		$result = parent::_del();
		if(!$result){
			$this->err_out($this->getError());
		}
		
		
		$this->add_log("删除字段【{$result}】信息",'role');
		$this->data_out($result);
		
	}
	
	
}
